﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Framework
{
    public abstract class Control : UIElement
    {
        static Control()
        {
            RegisterType(typeof(Control), typeof(UIElement));

            RegisterProp(typeof(Control), "IsTabStop", typeof(bool), null);
            RegisterProp(typeof(Control), "TabIndex", typeof(int), null);
            RegisterProp(typeof(Control), "Template", typeof(double), null);
            RegisterProp(typeof(Control), "TabNavigation", typeof(ControlTemplate), null);
            RegisterProp(typeof(Control), "Padding", typeof(Thickness), null);
            RegisterProp(typeof(Control), "HorizontalContentAlignment", typeof(HorizontalAlignment), null);
            RegisterProp(typeof(Control), "VerticalContentAlignment", typeof(VerticalAlignment), null);
            RegisterProp(typeof(Control), "Background", typeof(Brush), null);
            RegisterProp(typeof(Control), "BorderBrush", typeof(Brush), null);
            RegisterProp(typeof(Control), "ActualWidth", typeof(double), null);
            RegisterProp(typeof(Control), "BorderThickness", typeof(Thickness), null);
            RegisterProp(typeof(Control), "FontFamily", typeof(FontFamily), null);
            RegisterProp(typeof(Control), "Foreground", typeof(Brush), null);
            RegisterProp(typeof(Control), "FontWeight", typeof(FontWeight), null);
            RegisterProp(typeof(Control), "FontStyle", typeof(FontStyle), null);
            RegisterProp(typeof(Control), "FontStretch", typeof(FontStretch), null);
            RegisterProp(typeof(Control), "IsEnabled", typeof(bool), null);
            RegisterProp(typeof(Control), "DefaultStyleKey", typeof(Object), null);
        }

        public UIElement ImplementationRoot { get; set; }
      
        //public ControlDelegate[] OnEvent { get{ throw new NotImplementedException(); } }

        //public event DependencyPropertyChangedEventHandler IsEnabledChanged;

        public bool Focus()
        {
            throw new NotImplementedException();
        }

        public Boolean ApplyTemplate()
        {

            throw new NotImplementedException();
        }
    }


    public sealed class Border : UIElement
    {
        static Border()
        {
            RegisterType(typeof(Border), typeof(UIElement));
            RegisterProp(typeof(Border), "BorderBrush", typeof(Brush), null);
            RegisterProp(typeof(Border), "BorderThickness", typeof(Thickness), null);
            RegisterProp(typeof(Border), "Background", typeof(Brush), null);
            RegisterProp(typeof(Border), "CornerRadius", typeof(CornerRadius), null);
            RegisterProp(typeof(Border), "Padding", typeof(Thickness), null);
            RegisterProp(typeof(Border), "Child", typeof(UIElement), null);
        }

        public Border() { ; }
    }

    public class ContentControl : Control
    {
        static ContentControl()
        {
            RegisterType(typeof(ContentControl), typeof(Control));

            RegisterProp(typeof(ContentControl), "ContentTemplate", typeof(DataTemplate), null);
            RegisterProp(typeof(ContentControl), "Content", typeof(Object), null);
        }

        public ContentControl() { ; }
    }

    public enum ClickMode
    {
        Release,
        Press,
        Hove
    }

#region Button
    public abstract class ButtonBase : ContentControl
    {
        static ButtonBase()
        {
            RegisterType(typeof(ButtonBase), typeof(ContentControl));

            RegisterProp(typeof(ButtonBase), "ClickMode", typeof(ClickMode), null);
            RegisterProp(typeof(ButtonBase), "IsFocused", typeof(Boolean), null);
            RegisterProp(typeof(ButtonBase), "IsMouseOver", typeof(Boolean), null);
            RegisterProp(typeof(ButtonBase), "IsPressed", typeof(Boolean), null);
            RegisterProp(typeof(ButtonBase), "Command", typeof(ICommand), null);
            RegisterProp(typeof(ButtonBase), "CommandParameter", typeof(Object), null);
        }

        public event RoutedEventHandler Click;
    }

    public class Button : ButtonBase
    {
        public virtual void OnApplyTemplate()
        {
            throw new NotImplementedException();
        }
    }
#endregion Button


#region Panel
    public abstract class Panel : UIElement
    {
        static Panel()
        {
            RegisterType(typeof(Panel), typeof(UIElement));

            RegisterProp(typeof(Panel), "Background", typeof(Brush), null);
            RegisterProp(typeof(Panel), "IsItemsHost", typeof(Boolean), null);
        }

        public List<UIElement> Children { get; internal set; }
    }

    public class Canvas : Panel
    {
        static Canvas()
        {
            RegisterType(typeof(Canvas), typeof(Panel));

            RegisterProp(typeof(Canvas), "Left", typeof(double), null);
            RegisterProp(typeof(Canvas), "Top", typeof(double), null);
            RegisterProp(typeof(Canvas), "ZIndex", typeof(double), null);
        }
    }

    public class Grid : Panel
    {
        static Grid()
        {
            RegisterType(typeof(Grid), typeof(Panel));

            RegisterProp(typeof(Grid), "ShowGridLines", typeof(Boolean), null);
            RegisterProp(typeof(Grid), "Row", typeof(Int32), 0);
            RegisterProp(typeof(Grid), "Column", typeof(Int32), 0);
            RegisterProp(typeof(Grid), "RowSpan", typeof(Int32), 1);
            RegisterProp(typeof(Grid), "ColumnSpan", typeof(Int32), 1);
        }
    }
#endregion Panel

    public sealed class Image : UIElement
    {
        static Image()
        {
            RegisterType(typeof(Image), typeof(UIElement));

            RegisterProp(typeof(Image), "Stretch", typeof(Stretch), null);
            //RegisterProp(typeof(Image), "Source", typeof(ImageSource), null);
        }

        //public event EventHandler<ExceptionRoutedEventArgs> ImageFailed;
        public event EventHandler<RoutedEventArgs> ImageOpened;

        public Image() { ; }
    }

    public enum TextWrapping
    {
        NoWrap = 1,
        Wrap,
    }

    public sealed class TextBlock : UIElement
    {
        static TextBlock()
        {
            RegisterType(typeof(TextBlock), typeof(UIElement));

            RegisterProp(typeof(TextBlock), "FontSize", typeof(Double), null);
            RegisterProp(typeof(TextBlock), "FontFamily", typeof(FontFamily), null);
            RegisterProp(typeof(TextBlock), "FontWeight", typeof(FontWeight), null);
            RegisterProp(typeof(TextBlock), "FontStyle", typeof(FontStyle), null);
            RegisterProp(typeof(TextBlock), "FontStretch", typeof(FontStretch), null);
            RegisterProp(typeof(TextBlock), "Foreground", typeof(Brush), null);
            RegisterProp(typeof(TextBlock), "TextWrapping", typeof(TextWrapping), null);
            RegisterProp(typeof(TextBlock), "TextTrimming", typeof(TextTrimming), null);
            RegisterProp(typeof(TextBlock), "TextAlignment", typeof(TextAlignment), null);
            RegisterProp(typeof(TextBlock), "Text", typeof(String), null);
            RegisterProp(typeof(TextBlock), "Padding", typeof(Thickness), null);
            RegisterProp(typeof(TextBlock), "LineHeight", typeof(Double ), null);
            //RegisterProp(typeof(TextBlock), "LineStackingStrategy", typeof(LineStackingStrategy), null);
            //RegisterProp(typeof(TextBlock), "TextDecorations", typeof(Collection<TextDecoration>), null);
            RegisterProp(typeof(TextBlock), "Inlines", typeof(Collection<Inline>), null);
            RegisterProp(typeof(TextBlock), "FontSource", typeof(FontSource), null);
            RegisterProp(typeof(TextBlock), "BaselineOffset", typeof(Double), null);
        }

        public TextBlock() { ; }
    }

    public partial class TextBox : Control
    {
        
    }
}
